package cn.wolfcode.luowowo.controller;

import cn.wolfcode.luowowo.domain.*;
import cn.wolfcode.luowowo.service.*;
import cn.wolfcode.luowowo.util.JsonResult;
import com.fasterxml.jackson.core.JsonEncoding;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("destinations")
public class DestinationController {

    @Autowired
    private IRegionService regionService;

    @Autowired
    private IDestinationService destinationService;

    @Autowired
    private IStrategyCatalogService strategyCatalogService;

    @Autowired
    private IStrategyService strategyService;
    @Autowired
    private ITravelService travelService;
    //查询热门目的地
    @GetMapping("/hotRegion")
    public Object hotRegion(){
        //查询出热门区域并把数据返回前端
        List<Region> list=regionService.queryHotRegion();
        return JsonResult.success(list);
    }

    //查询区域下的目的地
    @GetMapping("/search")
    public Object search(String regionId){
        //根据区域id查询出相关联的目的地，然后将数据返回给前端
        List<Destination> list=destinationService.queryByRegionIdForApi(regionId);
        return JsonResult.success(list);
    }

    //导航吐司
    @GetMapping("/toasts")
    public Object toasts(String destId){
        List<Destination> toasts = destinationService.getToasts(destId);
        return JsonResult.success(toasts);
    }

    //当前目的地
    @GetMapping("/detail")
    public Object detail(String id){
        return JsonResult.success(destinationService.get(id));
    }

    //当前目的地下所有攻略分类
    @GetMapping("/catalogs")
    public Object catalogs(String destId){
       List<StrategyCatalog> catalogs= strategyCatalogService.queryCatalogsByDestId(destId);
       return JsonResult.success(catalogs);
    }

    //点击量前3的攻略文章
    @GetMapping("/strategies/viewnumTop3")
    public Object viewnumTop3(String destId){
        List<Strategy> list=strategyService.viewnumTop3(destId);
        return JsonResult.success(list);
    }

    //点击量前3的游记文章
    @GetMapping("/travels/viewnumTop3")
    private Object travelsViewnumTop3(String destId){
        List<Travel> travels = travelService.viewnumTop3(destId);
        return JsonResult.success(travels);
    }
}
